<?php

/**
* @file
* Contains \Drupal\discogs2marc\Form\SearchForm.
*/

namespace Drupal\discogs2marc\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Configure Database Source of discogs2marc
*/
class SearchForm extends FormBase {
	/**
	* {@inheritdoc}
	*/
	public function getFormId() {
		return 'discogs2marc_search';
	}
	
	/**
	* {@inheritdoc}
	*/
	public function buildForm(array $form, FormStateInterface $form_state) {
		$consumerkey = $this->config('discogs2marc.api')->get('consumerkey');
		$consumersecret = $this->config('discogs2marc.api')->get('consumersecret');
		
		$url=sprintf('https://api.discogs.com/releases/8300580');
		$data = (string) \Drupal::httpClient()->get($url)->getBody();
		$r=json_decode($data);
		var_dump($r);
		
		$form['title']=array(
			'#type' => 'item',
			'#title' => t('Title'),
			'#markup' => $r->title,
		);
		
		foreach($r->tracklist as $t) {
			$rows[]=$t->title;
		}
		
		$form['tracklist']=array(
			'#type' => 'item',
			'#title' => t('Tracklist'),
			'#markup' => implode('<br/>',$rows),
		);
		
		$form['consumerkey']=array(
			'#markup' => $consumerkey . $consumersecret 
		);

		return $form;
	}

	/**
	* {@inheritdoc}
	*/
	public function validateForm(array &$form, FormStateInterface $form_state) {
	}

	/**
	* {@inheritdoc}
	*/
	public function submitForm(array &$form, FormStateInterface $form_state) {
	}
}
?>

